<nav class="side-nav">
  {{ if .Site.Params.use_advanced_docs }}
    <noscript>Please enable javascript to use dropdown navigation</noscript>
    {{ $version := .CurrentSection.Params.version }}
    {{ .Render "versions" }}
    {{ .Render "search" }}
    {{ if $version }}
      {{ $tocTemplateName := index (index $.Site.Data.docs "toc-mapping") $version }}
      {{ if not $tocTemplateName }}
        {{ $tocTemplateName = "default" }}
      {{ end }}
      {{ $toc := (index $.Site.Data "docs" $tocTemplateName).toc }}
      {{ range $toc }}
      <ul>
        <li>
          <p class="heading">{{ .title }}</p>
        </li>
        <li>
          <ul>
            {{ range .subfolderitems }}
            <li>
              {{ $url := (index (print "/docs/" $version .url "/")) }}
              <a href="{{ $url }}" {{ if (eq $.Page.RelPermalink $url) }}class="active" {{ end }}>{{ .page }}</a>
              {{ if not (eq $.Page.RelPermalink (print "/docs/" $version "/")) }}
                {{ range .subitems }}
                {{ $itemUrlTrim := (strings.TrimSuffix "/" ( strings.TrimSuffix "/" $url) ) }}
                {{ $subUrl := (index (print "/docs/" $version .suburl "/")) }}
                {{ $currentPageTrim := (strings.TrimSuffix "/" ( strings.TrimSuffix "/" $.Page.RelPermalink) ) }}
                {{ $activeSubitem := or (eq $.Page.RelPermalink $url) (in (relURL $.Page.RelPermalink) (relURL $url)) }}
                {{ if or ($activeSubitem) (strings.Contains $itemUrlTrim $currentPageTrim) }}
                  <ul>
                    <li>
                      <a href="{{ $subUrl }}" {{ if  (eq $.Page.RelPermalink $subUrl) }}class="active" {{ end }}>{{ .subpage }}</a>
                    </li>
                  </ul>
                {{ end }}
              {{ end }}
              </li>
              {{ end }}
            {{ end }}
          </ul>
        </li>
      </ul>
      {{ end }}
    {{ end }}
  {{ else }}
    <ul>
      {{ $currentPage := . }}
      {{ range .Site.Menus.docs }}
        <li><a href="{{ .URL }}" {{ if (eq $currentPage.RelPermalink .URL) }}class="active"{{ end }}>{{ .Name }}</a></li>
      {{ end }}
    </ul>
  {{ end }}
  </nav>
